<!--
 * @ Author: hongjiazhun
 * @ Create Time: 2023-03-10 20:01:09
 * @ Modified by: hongjiazhun
 * @ Modified time: 2023-03-29 23:08:52
 * @ Description:个人排班历史
 -->

<template>
  <div class="app-container">
    <avue-crud
      :search.sync="searchParams"
      v-model="form"
      @on-load="onLoad"
      :page.sync="page"
      ref="crud"
      :data="tableData"
      :option="option"
      :table-loading="loading"
      @selection-change="selectionChange"
      @refresh-change="refreshChange"
      @size-change="sizeChange"
      @current-change="currentChange"
      @search-change="searchChange"
      @search-reset="resetChange"
    >
      <!-- <template slot-scope="scope" slot="menuLeft">
        <el-button
          circle
          icon="el-icon-document-copy"
          size="small"
          title="导出"
        ></el-button>
      </template> -->
    </avue-crud>
  </div>
</template>

<script>
import { bsaeUrl } from "@/config/index";
import { getToken } from "@/utils/auth";
import { getList } from "@/api/arrangeClasses/record";
import { mapGetters } from "vuex";

export default {
  name: "record",
  data() {
    return {
      tableData: [],
      option: {
        border: true,
        columnBtn: false,
        delBtn: false,
        editBtn: false,
        addBtn: false,
        // selection: true,
        tip: false,
        // dialogDrag: true,
        searchMenuSpan: 4,
        menu: false,
        column: [
          {
            label: "年度",
            prop: "scheduleYear",
            type: "year",
            format: "yyyy",
            valueFormat: "yyyy",
            search: true,
            searchSpan: 5,
          },
          {
            label: "发布时间",
            prop: "createTime",
          },
          {
            label: "带班领导",
            prop: "leaderName",
          },
          {
            label: "排班类型",
            prop: "scheduleType",
            search: true,
            type: "select",
            searchSpan: 5,
            props: {
              label: "dictLabel",
              value: "dictValue",
            },
            dicUrl: `${bsaeUrl}/system/dict/data/list?dictType=xmu_schedule_type`,
            dicHeaders: {
              Authorization: "Bearer " + getToken(),
            },
            dicFormatter: (res) => {
              const { rows = [], code } = res;
              return code === 200 ? rows : [];
            },
          },
          {
            label: "排班日期",
            prop: "scheduleDay",
            search: true,
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
          },
        ],
      },
      form: {},
      loading: false,
      searchParams: {},
      page: {
        total: 0,
        currentPage: 1,
        pageSize: 10,
      },
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  methods: {
    // 获取数据
    async onLoad() {
      this.loading = true;
      const { currentPage = 1, pageSize } = this.page;
      const { deptId, userId } = this.userInfo;
      // 设置请求参数
      const params = {
        pageNum: currentPage,
        pageSize,
        deptId,
        userId,
        ...this.searchParams,
      };
      const { code, rows = [], total } = await getList(params);
      this.tableData = code === 200 ? rows : [];
      this.loading = false;
      // 设置总条数
      this.page.total = total;
    },
    // 刷新
    refreshChange() {
      this.onLoad();
    },
    // 条数
    sizeChange(val) {
      this.page.currentPage = 1;
      this.page.pageSize = val;
    },
    // 页数
    currentChange(val) {
      this.page.currentPage = val;
    },
    resetChange(item) {
      this.onLoad();
    },
    searchChange(params, done) {
      this.onLoad();
      done();
    },
    // 多选
    selectionChange(selection) {
      this.selectionData = selection;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>